package com.micro.school.system.controller.base;

import com.micro.school.common.core.context.SecurityContextHolder;
import com.micro.school.common.core.web.controller.BaseController;
import com.micro.school.common.core.web.domain.AjaxResult;
import com.micro.school.common.core.web.page.TableDataInfo;
import com.micro.school.system.domain.SchoolPayWay;
import com.micro.school.system.service.SchoolPayWayService;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (SchoolPayWay)表控制层
 *
 * @author makejava
 * @since 2025-08-08 19:07:22
 */
@RestController
@RequestMapping("/schoolPayWay")
public class SchoolPayWayController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private SchoolPayWayService schoolPayWayService;

    /**
     * 分页查询
     *
     * @param schoolPayWay 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public TableDataInfo queryByPage(SchoolPayWay schoolPayWay) {
        startPage();
        List<SchoolPayWay> schoolPayWays = this.schoolPayWayService.queryByPage(schoolPayWay);
        return getDataTable(schoolPayWays);
    }

    @GetMapping("/list")
    public AjaxResult schoolPayWayList(SchoolPayWay schoolPayWay) {
        List<SchoolPayWay> schoolPayWays = this.schoolPayWayService.queryByPage(schoolPayWay);
        return success(schoolPayWays);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Integer id) {
        return success(this.schoolPayWayService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param schoolPayWay 实体
     * @return 新增结果
     */
    @PostMapping
    public AjaxResult add(@RequestBody SchoolPayWay schoolPayWay) {
        schoolPayWay.setTenantId(Integer.valueOf(SecurityContextHolder.getUserTenantId()));
        return success(this.schoolPayWayService.insert(schoolPayWay));
    }

    /**
     * 编辑数据
     *
     * @param schoolPayWay 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SchoolPayWay schoolPayWay) {
        return success(this.schoolPayWayService.update(schoolPayWay));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public AjaxResult deleteById(Integer id) {
        return success(this.schoolPayWayService.deleteById(id));
    }

}

